package com.example.dangerouscargodriver.adapter;


import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.viewpager.widget.PagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class BannerViewAdapter extends PagerAdapter {

    private List<ImageView> mImageList = null;

    public BannerViewAdapter(){
        mImageList = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mImageList.size();
    }
    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        if(mImageList != null && mImageList.size() > position) {
            ImageView imageView = mImageList.get(position);
            container.addView(imageView);
            return imageView;
        }
        else{
            return null;
        }
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }

    public void setImageList(List<ImageView> list){
        mImageList = list;
    }
}
